#include "Blob.h"

namespace blobDetection
{

int Blob::MAX_NBLINE = 4000;   

//==================================================
//class Blob
//==================================================
Blob::Blob(BlobDetection *parent)
{
	this->parent = parent;
	line = new int[MAX_NBLINE];  // stack of index
	nbLine = 0;
	ok = true;
}


Blob::Blob()
{
	line = new int[MAX_NBLINE];  // stack of index
	nbLine = 0;
	ok = false;
}

Blob::Blob(bool isOk)
{
	line = new int[MAX_NBLINE];  // stack of index
	nbLine = 0;
	ok = isOk;
}

bool Blob::isOk()
{
	return ok;
}

void Blob::setParent(BlobDetection *parent)
{
	this->parent = parent;
	ok = true;
}

EdgeVertex Blob::getEdgeVertexA(int iEdge)
{
	if (iEdge*2<parent->nbLineToDraw*2)
	{
		int x = line[iEdge*2];
		return parent->getEdgeVertex(x);
	}
	else
		return EdgeVertex(false);
}

EdgeVertex Blob::getEdgeVertexB(int iEdge)
{
	if ((iEdge*2+1)<parent->nbLineToDraw*2)
		return parent->getEdgeVertex(line[iEdge*2+1]);
	else
		return EdgeVertex(false);
}

Blob::~Blob()
{
	//delete [] line;
}

int Blob::getEdgeNb()
{
	return nbLine;
}

void Blob::update()
{
	w = (xMax-xMin);
	h = (yMax-yMin);
	x = 0.5*(xMax+xMin);
	y = 0.5*(yMax+yMin);

	nbLine /= 2;  
}


};